package com.shen.accountbook.bean.temp;

import android.os.Parcel;
import android.os.Parcelable;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Keep;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.ToOne;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import com.shen.accountbook.greendao.DaoSession;
import com.shen.accountbook.greendao.ThirdSortBeanDao;

import java.util.List;
import com.shen.accountbook.greendao.NoteBeanTempDao;

/**
 *  记一笔 --- 多个小类别的model
 */
@Entity
public class NoteBeanTemp implements Parcelable {

    @Id
    private Long id;

    @NotNull
    private Long first_sort_id;
    @NotNull
    private Long second_sort_id;
    @NotNull
    private Long third_sort_id;

    @ToOne(joinProperty = "third_sort_id")
    private ThirdSortBean thirdSortBean;


    /** 金额 */
    @NotNull
    private float money;
    /** 备注 */
    private String remarks;
    /** 图片 */
    private String img;
    /** 时间 */
    @NotNull
    private String createDate;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 1511409332)
    private transient NoteBeanTempDao myDao;
    @Generated(hash = 1349534733)
    public NoteBeanTemp(Long id, @NotNull Long first_sort_id,
            @NotNull Long second_sort_id, @NotNull Long third_sort_id, float money,
            String remarks, String img, @NotNull String createDate) {
        this.id = id;
        this.first_sort_id = first_sort_id;
        this.second_sort_id = second_sort_id;
        this.third_sort_id = third_sort_id;
        this.money = money;
        this.remarks = remarks;
        this.img = img;
        this.createDate = createDate;
    }
    @Generated(hash = 1271749950)
    public NoteBeanTemp() {
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getFirst_sort_id() {
        return this.first_sort_id;
    }
    public void setFirst_sort_id(Long first_sort_id) {
        this.first_sort_id = first_sort_id;
    }
    public Long getSecond_sort_id() {
        return this.second_sort_id;
    }
    public void setSecond_sort_id(Long second_sort_id) {
        this.second_sort_id = second_sort_id;
    }
    public Long getThird_sort_id() {
        return this.third_sort_id;
    }
    public void setThird_sort_id(Long third_sort_id) {
        this.third_sort_id = third_sort_id;
    }
    public float getMoney() {
        return this.money;
    }
    public void setMoney(float money) {
        this.money = money;
    }
    public String getRemarks() {
        return this.remarks;
    }
    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }
    public String getImg() {
        return this.img;
    }
    public void setImg(String img) {
        this.img = img;
    }
    public String getCreateDate() {
        return this.createDate;
    }
    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }
    @Generated(hash = 1322110414)
    private transient Long thirdSortBean__resolvedKey;
    /** To-one relationship, resolved on first access. */
    @Generated(hash = 1431691498)
    @Keep
    public ThirdSortBean getThirdSortBean() {
        Long __key = this.third_sort_id;
        if (thirdSortBean__resolvedKey == null
                || !thirdSortBean__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            ThirdSortBeanDao targetDao = daoSession.getThirdSortBeanDao();

            ThirdSortBean thirdSortBeanNew = null;
            List<ThirdSortBean> list = targetDao.queryBuilder()
                    .where(ThirdSortBeanDao.Properties.Third_sort_id.eq(__key)).list();

            if(list != null && list.size() > 0){
                thirdSortBeanNew = list.get(0);
            }

            synchronized (this) {
                thirdSortBean = thirdSortBeanNew;
                thirdSortBean__resolvedKey = __key;
            }
        }
        return thirdSortBean;
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1271294173)
    public void setThirdSortBean(@NotNull ThirdSortBean thirdSortBean) {
        if (thirdSortBean == null) {
            throw new DaoException(
                    "To-one property 'third_sort_id' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.thirdSortBean = thirdSortBean;
            third_sort_id = thirdSortBean.getId();
            thirdSortBean__resolvedKey = third_sort_id;
        }
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1552710269)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getNoteBeanTempDao() : null;
    }

    @Override
    public String toString() {
        return "NoteBeanTemp{" +
                "id=" + id +
                ", first_sort_id=" + first_sort_id +
                ", second_sort_id=" + second_sort_id +
                ", third_sort_id=" + third_sort_id +
                ", thirdSortBean=" + thirdSortBean +
                ", money=" + money +
                ", remarks='" + remarks + '\'' +
                ", img='" + img + '\'' +
                ", createDate=" + createDate +
                ", daoSession=" + daoSession +
                ", myDao=" + myDao +
                ", thirdSortBean__resolvedKey=" + thirdSortBean__resolvedKey +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(this.id);
        dest.writeValue(this.first_sort_id);
        dest.writeValue(this.second_sort_id);
        dest.writeValue(this.third_sort_id);
        dest.writeParcelable(this.thirdSortBean, flags);
        dest.writeFloat(this.money);
        dest.writeString(this.remarks);
        dest.writeString(this.img);
        dest.writeString(this.createDate);
    }

    protected NoteBeanTemp(Parcel in) {
        this.id = (Long) in.readValue(Long.class.getClassLoader());
        this.first_sort_id = (Long) in.readValue(Long.class.getClassLoader());
        this.second_sort_id = (Long) in.readValue(Long.class.getClassLoader());
        this.third_sort_id = (Long) in.readValue(Long.class.getClassLoader());
        this.thirdSortBean = in.readParcelable(ThirdSortBean.class.getClassLoader());
        this.money = in.readFloat();
        this.remarks = in.readString();
        this.img = in.readString();
        this.createDate = in.readString();
    }

    public static final Parcelable.Creator<NoteBeanTemp> CREATOR = new Parcelable.Creator<NoteBeanTemp>() {
        @Override
        public NoteBeanTemp createFromParcel(Parcel source) {
            return new NoteBeanTemp(source);
        }

        @Override
        public NoteBeanTemp[] newArray(int size) {
            return new NoteBeanTemp[size];
        }
    };
}
